var romanToInt = function (s) {
  const map = {
    'I': 1,
    'v': 5,
    'x': 10,
    'L': 50,
    'C': 100,
    'D': 500,
    'M': 1000,
  }
  let result = 0
  for (let i = 0; i < s.length; i++) {
    let curNum = map[s[i]]
    let nextNum = map[s[i + 1]]
    if (curNum < nextNum) {
      result -= curNum
    } else {
      result += curNum
    }
  }
  return result
};
console.log(romanToInt('III'));